package com.imooc.service.impl;

import com.imooc.mapper.CategoryMapper;
import com.imooc.mapper.CategoryMapperCustom;
import com.imooc.pojo.Category;
import com.imooc.pojo.VO.CategoryVO;
import com.imooc.pojo.VO.NewItemVO;
import com.imooc.service.CategoryService;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author lihongyu
 * @CreateTime 2021-08-10 14:24
 * @Description 分类业务逻辑实现类
 */
@Service
public class CategoryServiceImpl implements CategoryService {

    @Resource
    private CategoryMapper categoryMapper;

    @Resource
    private CategoryMapperCustom categoryMapperCustom;

    /**
     * 获取一级分类列表
     *
     * @return 一级分类列表
     */
    @Override
    public List<Category> getRootCategoryList() {
        Example example = new Example(Category.class);
        example.createCriteria().andEqualTo("type",1);
        return categoryMapper.selectByExample(example);
    }

    /**
     * 根据分类编码获取分类下六个最新商品信息
     *
     * @param rootCatId 一级分类编码
     * @return 六个最新商品信息
     */
    @Override
    public List<NewItemVO> getSixNewItemsByRootCatId(Integer rootCatId) {
        Map<String,Object> paramMap = new HashMap<>(11);
        paramMap.put("rootCatId",rootCatId);
        return categoryMapperCustom.getSixNewItemsByRootCatId(paramMap);
    }

    /**
     * 根据一级分类编码获取子分类列表
     *
     * @param categoryId 一级分类编码
     * @return 子分类编码
     */
    @Override
    public List<CategoryVO> getSubCategoryListByRootCategoryId(Integer categoryId) {
        return categoryMapperCustom.getSubCategoryListByRootCategoryId(categoryId);
    }
}
